<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('明细展示')" />
    <th:block th:include="include :: select2-css" />
    <th:block th:include="include :: bootstrap-fileinput-css" />
</head>
<body class="gray-bg">
     <div class="container-div">
        <div class="row">
            <div class="col-sm-12 search-collapse">
                <form id="formId">
                    <div class="select-list">
                        <ul>
                            <li>
                                <label>项目名称：</label>
                                <input type="text" name="projectName"/>
                            </li>
                            <li>
                                <label>姓名：</label>
                                <input type="text" name="userName"/>
                            </li>
                            <li>
                                <label>年份：</label>
                                <input type="text" name="year"/>
                            </li>
                            <li>
                                <label>年假时长（小时）</label>
                                <input type="text" name="yearHolTotal"/>
                            </li>
                            <li>
                                <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
                                <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
                            </li>
                        </ul>
                    </div>
                </form>
            </div>
            <div class="btn-group-sm" id="toolbar" role="group">
                <a class="btn btn-success" onclick="$.operate.add()" shiro:hasPermission="hrm:sysHoliday:add">
                    <i class="fa fa-plus"></i> 新增
                </a>
                <a class="btn btn-success single disabled" onclick="$.operate.edit()" shiro:hasPermission="hrm:sysHoliday:update">
                    <i class="fa fa-edit"></i> 修改
                </a>
                <a class="btn btn-danger multiple disabled" onclick="$.operate.removeAll()" shiro:hasPermission="hrm:sysHoliday:delete">
                    <i class="fa fa-remove"></i> 删除
                </a>
                <a class="btn btn-info" onclick="$.table.importExcel()" shiro:hasPermission="hrm:sysHoliday:import">
                    <i class="fa fa-upload"></i> 导入明细
                </a>
                <a class="btn btn-warning" onclick="exportDetailExcel()" shiro:hasPermission="hrm:sysHoliday:detailExport">
                    <i class="fa fa-download"></i> 导出明细
                </a>
            </div>

            <div class="col-sm-12 select-table table-striped">
                <table id="bootstrap-table"></table>
            </div>
        </div>
    </div>
     <th:block th:include="include :: footer" />
     <th:block th:include="include :: bootstrap-fileinput-js" />
     <th:block th:include="include :: select2-js" />
    <script th:inline="javascript">
        var prefix = ctx + "hrm/sysHoliday";
        $(function() {
              var options = {
                    url: prefix + "/detailList",
                    createUrl: prefix + "/add",
                    updateUrl: prefix + "/edit/{id}",
                    removeUrl: prefix + "/remove",
                  detailExportUrl:prefix + "/detailExport",
                  importUrl: prefix + "/importData",
                    importTemplateUrl: prefix + "/importTemplate",
                    uniqueId:"holidayUuid",
                    modalName: "休假信息",
                    columns: [{
                        checkbox: true
                    },
                        {
                            field: 'holidayUuid',
                            title: '主键',
                            visible: false
                        },
                        {
                            field: 'serialNum',
                            title: '序号',
                            visible: true
                        },
                        {
                            field: 'projectName',
                            title: '项目名称'
                        },
                        {
                            field: 'userName',
                            title: '员工名称'
                        },
                        {
                            field: 'year',
                            title: '年份'
                        },
                        {
                            field: 'yearHolTotal',
                            title: '年假时长(小时）'
                        },
                        {
                            field: 'holidayDate',
                            title: '休假日期'
                        },
                        {
                            field: 'yearHolDate',
                            title: '已休年假时长(小时）'
                        },
                        {
                            field: 'casuHolDate',
                            title: '已休事假时长(小时）'
                        },
                        {
                            field: 'sickHolDate',
                            title: '已休病假时长(小时）'
                        },
                        {
                            field: 'bak',
                            title: '备注'
                        }]
                };
                $.table.init(options);
        });

        function exportDetailExcel(){
            var rows=$.table.selectColumns(table.options.uniqueId);
            var msg = "确定导出全部个人明细吗？"
            if(rows.length!=0){
                msg = "确定导出勾选的"+rows.length+"条数据吗？"
            }
            $.modal.confirm(msg, function() {
                var params = $("#" + table.options.id).bootstrapTable('getOptions');
                var dataParam = $("#formId").serializeArray();
                dataParam.push({ "name": "orderByColumn", "value": params.sortName });
                dataParam.push({ "name": "isAsc", "value": params.sortOrder });
                if(rows.length!=0){
                    dataParam.push({"name": "ids", "value": rows.join()});
                }
                $.modal.loading("正在导出数据，请稍后...");
                $.post(table.options.detailExportUrl, dataParam, function(result) {
                    if (result.code == web_status.SUCCESS) {
                        window.location.href = ctx + "common/download?fileName=" + encodeURI(result.msg) + "&delete=" + true;
                    } else if (result.code == web_status.WARNING) {
                        $.modal.alertWarning(result.msg)
                    } else {
                        $.modal.alertError(result.msg);
                    }
                    $.modal.closeLoading();
                });
            });
        }
    </script>
</body>

<!-- 导入区域 -->

<script id="importTpl" type="text/template">
    <form enctype="multipart/form-data" class="mt20 mb10">
        <div class="col-xs-offset-1">
            <input type="file" id="file" name="file"/>
            <div class="mt10 pt5">
                <a onclick="$.table.importTemplate()" class="btn btn-default btn-xs" shiro:hasPermission="hrm:sysHoliday:template"><i class="fa fa-file-excel-o"></i> 下载模板</a>
            </div>
            <font color="red" class="pull-left mt10">
                提示：仅允许导入“xls”或“xlsx”格式文件！！！
            </font>
        </div>
    </form>
</script>
</html>